<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>初识setup</title>
</head>
<body>
    <div id="app"></div>
</body>
<script src="https://unpkg.com/vue@next"></script>
<script>
    const app = Vue.createApp({
        data() {
            return {
                name: 'andy',
                sex: '男',
                age: 25
            }
        },
        template: `
            <div>
                <h1>我的信息</h1>
                <h2>姓名：andy</h2>
                <h2>性别：sex</h2>
                <h2>年龄：age</h2>
                <button @click="sayHello" > 打招呼</button>
                <button @click="test1" > 测试vue2.x中的函数访问vue.3setup中的数据，方法</button>
                <button @click="test2" > 测试vue.3中的函数访问vue2.x的数据方法</button>
            </div>
        `,
        methods: {
            test1(){
                console.log(`姓名：${this.name} 年龄:${this.age},性别：${this.sex},sayhello:${this.sayHello}`);
            },
            sayHello(){
                alert(`您好！我是${this.name}, 今年：${this.age} 岁！`)
            }
        },
        setup(props){
            let name ='213';
            let age =25;
            function sayHello(){
                console.log('sayhello -->',name,age);
                alert(`您好 我是${name},今年${age}岁`)
            }
            function test2(){
                return{name,age,sayHello,test2}
            }
        }
    })

    const vm = app.mount("#app")
</script>
</html>